package Thread2;

import java.util.Scanner;

public class Demo24 {
    public static void main(String[] args) {
        Object locker = new Object();

        Thread t1 = new Thread(() -> {
            System.out.println("t1 wait 之前");

            synchronized(locker){
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            System.out.println("t1 wait 之后");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2 wait 之前");

            synchronized(locker){
                try {
                    locker.wait(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            System.out.println("t2 wait 之后");
        });

        Thread t3 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入任意内容,唤醒一个线程:");
            scanner.next();
            synchronized (locker){
                // locker.notify();
                locker.notifyAll();
            }

            // System.out.println("输入任意内容,唤醒另一个线程:");
            // scanner.next();
            // synchronized (locker){
            //     locker.notify();
            // }
        });

        t1.start();
        t2.start();
        t3.start();
    }
}
